<template>
    <div>
        <h2>修改页面</h2>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>科室名称</td>
                    <td><input type="text" v-model="pdate.tname"></td>
                </tr>
                <tr>
                    <td>科室人数</td>
                    <td><input type="text" v-model="pdate.personNum"></td>
                </tr>
                <tr>
                    <td>科室介绍</td>
                    <td>
                        <textarea name="" id="" cols="30" rows="10" v-model="pdate.thing"></textarea>
                    </td>
                </tr>
                <tr>
                    <td>创建时间</td>
                    <td><input type="date" v-model="pdate.strDate"></td>
                </tr>
                <tr>
                    <td> </td>
                    <td><input type="button" class="primary btn btn-primary" value="修改" @click="UpdateType"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref, reactive, onMounted } from 'vue';
import { useRouter,useRoute } from 'vue-router';

const router = useRouter();
const route = useRoute();


let pdate = reactive({
    id:route.query.id,
    tname: "",
    personNum: null,
    thing: "",
    strDate: "",
    state: 1,
    isDeleted: true
})
 
onMounted(() => {
    Fan();
})




//回显
const Fan = () => {
    
    alert(route.query.id);
    
    axios({
        url: "/api/Hotel/Fan",
        method: "get",
        params: {
            uid: route.query.id
        }
    }).then((res) => {
        Object.assign(pdate, res.data[0]);
        pdate.strDate = res.data[0].strDate.split("T")[0];
    }) 
}


const UpdateType = () => {

    


    if (pdate.tname == "") {
        alert("科室名称不能为空");
        return;
    }
    if (pdate.personNum == null) {
        alert("科室人数不能为空");
        return;
    }
    if (pdate.thing == "") {
        alert("科室介绍不能为空");
        return;
    }
    if (pdate.strDate == "") {
        alert("创建时间不能为空");
        return;
    }




    axios({
        url: "/api/Hotel/UpdateType",
        method: "put",
        data: pdate
    }).then((res) => {
        if (res.data > 0) {
            alert("修改成功");
            router.push("/ShowTypeView");
        } else if (res.data == -1) {
            alert("该科室已存在");
            return;
        } else {
            alert("修改失败");
            return;
        }
    })
}

</script>

<style scoped></style>